import os
from glob import glob
from wbox.gx.program import GxProgram
from wbox.gx.comment import GxCommentFile


class GxProject(object):
    def __init__(self, root):
        self.root = root

    def parameter(self):
        path = "%s\\Resource\\param.wpa" % (self.root)
        return path

    def programPath(self, name):
        return 
        
    def program(self, name):
        path = "%s\\Resource\\POU\\Body\\%s.wpg" % (self.root, name)
        return GxProgram(self, path)
        
    def programList(self):
        pattern = "%s\\Resource\\POU\\Body\\*.wpg" % (self.root,)
        def splitName(path):
            return os.path.splitext(os.path.split(path)[1])[0]
        return map(splitName, glob(pattern))
        
    def commentPath(self, name):
        path = "%s\\Resource\\Others\\%s.wcd" % (self.root, name)
        return path

    def comment(self, name):
        path = "%s\\Resource\\Others\\%s.wcd" % (self.root, name)
        comment = GxCommentFile()
        comment.load(path)
        return comment
        
